package com.example.calladapter;

import android.os.Build.VERSION_CODES;
import android.support.annotation.RequiresApi;
import java.lang.reflect.Type;
import retrofit2.Call;
import retrofit2.CallAdapter;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author GYL
 * @version 1.0
 * @dateTime 2020/6/11-18:15
 * @description
 */
public class CustomCallAdapter<T> implements CallAdapter<T, CustomCall<T>> {
  
  private final Type responseType;
  
  public CustomCallAdapter(Type responseType) {
    this.responseType = responseType;
    System.out.println(responseType.toString());
  }
  
  /**
   * 真正数据的类型，如Call<T> 中的 T，这个T会作为  Converter.Factory.responseConverter的第一个参数
   */
  @Override
  public Type responseType() {
    return responseType;
  }
  
  
  @Override
  public CustomCall<T> adapt(Call<T> call) {
    System.out.println("adapt");
    CustomCall<T> tCustomCall = new CustomCall<>(call);
    
    return tCustomCall;
  }
}
